-
-
Notifications
You must be signed in to change notification settings - Fork 6
Add ViewModelRegistrationType to IViewFor attribute #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introduces ViewModelRegistrationType to the IViewFor attribute and updates generator logic to support separate Splat registration for view models. Documentation, tests, and source generator code are updated to reflect the new option and ensure correct registration behavior.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #341 +/- ##
==========================================
- Coverage 40.04% 39.98% -0.06%
==========================================
Files 61 61
Lines 3389 3429 +40
Branches 389 395 +6
==========================================
+ Hits 1357 1371 +14
- Misses 1926 1948 +22
- Partials 106 110 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Added [ExcludeFromCodeCoverage] attribute to various test and sample classes across the project to exclude them from code coverage analysis. This helps ensure that code coverage metrics focus on production code rather than test scaffolding.
Deleted the [ExcludeFromCodeCoverage] attribute from several test-related classes to allow code coverage tools to include these files. This change may help improve visibility into test code coverage metrics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds the ViewModelRegistrationType property to the IViewForAttribute, enabling separate Splat registration for ViewModels alongside the existing View registration. This allows developers to automatically register ViewModels in the dependency injection container when configuring their Views.
Key Changes
- Added
ViewModelRegistrationTypeproperty to both generic and non-genericIViewForAttributevariants - Extended
IViewForInfomodel to includeSplatViewModelRegistrationTypefield - Updated source generator logic to process and generate separate ViewModel registrations
- Updated documentation and test examples to demonstrate the new feature
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ReactiveUI.SourceGenerators.Roslyn/IViewFor/Models/IViewForInfo.cs | Added SplatViewModelRegistrationType parameter to the model record and removed unused import |
| src/ReactiveUI.SourceGenerators.Roslyn/IViewFor/IViewForGenerator.Execute.cs | Added logic to extract and process ViewModelRegistrationType from attributes and generate corresponding ViewModel registrations |
| src/ReactiveUI.SourceGenerators.Roslyn/AttributeDefinitions.cs | Added ViewModelRegistrationType property to both IViewForAttribute variants with documentation; replaced hardcoded version strings with placeholder variables |
| src/ReactiveUI.SourceGenerators.Execute/TestViewWpf.cs | Updated example usage to demonstrate both RegistrationType and ViewModelRegistrationType properties |
| src/ReactiveUI.SourceGenerators.Execute/TestViewWpf2.cs | Added using System.Diagnostics.CodeAnalysis import |
| src/ReactiveUI.SourceGenerators.Execute/TestViewModel{partTwo}.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute/TestViewModel3.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute/TestViewModel2.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute/TestClassOAPH_VM.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute/TestAttribute.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute/Program.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute/Person.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute/InternalTestViewModel.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute.Nested3/Class1.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute.Nested2/Class1.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute.Nested1/Class1.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute.Maui/TestViewModel.cs | Added [ExcludeFromCodeCoverage] attribute |
| src/ReactiveUI.SourceGenerators.Execute.Maui/IViewForTest.cs | Added import for System.Diagnostics.CodeAnalysis |
| src/ReactiveUI.SourceGenerator.Tests/TestHelper.cs | Replaced obsolete VersionRange.AllStableFloating with VersionRange.AllStable |
| src/ReactiveUI.SourceGenerator.Tests/IVIEWFOR/IViewForGeneratorTests.FromIViewFor#ReactiveUI.SourceGenerators.IViewForAttribute.g.verified.cs | Updated verified test output to include new ViewModelRegistrationType property |
| src/ReactiveUI.SourceGenerators.Execute/TestWinFormsVMCHost.cs | Added import for System.Diagnostics.CodeAnalysis |
| src/ReactiveUI.SourceGenerators.Execute/TestWinFormsRCHost.cs | Added import for System.Diagnostics.CodeAnalysis |
| README.md | Updated documentation to mention both IViewFor and ViewModel registration options and updated example usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/ReactiveUI.SourceGenerators.Roslyn/IViewFor/IViewForGenerator.Execute.cs
Outdated
Show resolved
Hide resolved
...ewForGeneratorTests.FromIViewFor#ReactiveUI.SourceGenerators.IViewForAttribute.g.verified.cs
Outdated
Show resolved
Hide resolved
...ewForGeneratorTests.FromIViewFor#ReactiveUI.SourceGenerators.IViewForAttribute.g.verified.cs
Outdated
Show resolved
Hide resolved
src/ReactiveUI.SourceGenerators.Roslyn/IViewFor/IViewForGenerator.Execute.cs
Outdated
Show resolved
Hide resolved
Changed the grouping key from SplatRegistrationType to SplatViewModelRegistrationType in viewModelRegistrations to ensure correct grouping of ViewModel registration types.
Updated XML comments to specify that the ViewModel (T) is registered in the Splat service locator, instead of IViewFor<T>. This improves clarity for consumers of the attribute.
Clarifies XML documentation to specify that ViewModel (T) is registered in the Splat service locator, instead of IViewFor<T>. Adds new received test file for .NET 10.0 verifying the generated attribute code.
src/ReactiveUI.SourceGenerators.Roslyn/IViewFor/IViewForGenerator.Execute.cs
Outdated
Show resolved
Hide resolved
Added checks to skip processing registrations where ViewModelTypeName is null, empty, or whitespace. This prevents potential errors from invalid or incomplete registration data.
Simplifies vmType handling by removing redundant string.IsNullOrEmpty checks before prefixing with 'global::'. This change assumes vmType is always non-null and non-empty at this point in the code.
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
What kind of change does this PR introduce?
feature
What is the current behavior?
IViewFor can register a View in Splat
What is the new behavior?
Introduces ViewModelRegistrationType to the IViewFor attribute and updates generator logic to support separate Splat registration for view models. Documentation, tests, and source generator code are updated to reflect the new option and ensure correct registration behavior.
What might this PR break?
None, new feature
Please check if the PR fulfills these requirements
Other information: